GPy is a framework for Gaussian process based applications. It is design for speed and reliability. The main three pillars of its functionality are made of
In this tutorial we will have a look at the three main pillars, so you may be able to use Gaussian processes with ease of mind and without the complications of cutting edge research code.
In [1]:
import GPy, numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
In [2]:
X = np.random.uniform(0, 10, (200, 1))
f = np.sin(.3*X) + .3*np.cos(1.3*X)
f -= f.mean()
Y = f+np.random.normal(0, .1, f.shape)
In [3]:
plt.scatter(X, Y)
Out[3]:
In [4]:
m = GPy.models.GPRegression(X, Y)
m
Out[4]:
Changing parameters is as easy as assigning new values to the respective parameter:
In [5]:
m.rbf.lengthscale = 1.5
m
Out[5]:
The whole model gets updated automatically, when updating a parameter, without you having to interfere at all.
Change some parameters and plot the results, using the models plot()
function
What do the different parameters change in the result?
In [6]:
# Type your code here
The parameters can be optimized using gradient based optimization. The optimization routines are taken over from scipy. Running the optimization in a GPy model is a call to the models own optimize
method.
In [7]:
m.optimize(messages=1)
In [8]:
_ = m.plot()
In [9]:
# You can use different kernels to use on the data.
# Try out three different kernels and plot the result after optimizing the GP:
# See kernels using GPy.kern.<tab>
In [10]:
# Type your code here
Try saving a model using the models pickle(<name>)
function and load it again using GPy.load(<name>)
. The loaded model is fully functional and can be used as usual.
In [11]:
# Type your code here
We have put a lot of effort in stability of execution, so try to randomize a model using its randomize()
function, which randomized the models parameters. After optimization the result whould be very close to previous model optimizations.
In [12]:
# Type your code here
In [13]:
GPy.core.SparseGP?
In [24]:
GPy.core.SVGP?
We can easily run a sparse GP on above data by using the wrapper methods for running different GPy models:
GPy.models.<tab>
Use the GPy.models.SparseGPRegression
to run the above data using the sparse GP:
In [15]:
#Type your code here
Use the GPy.core.SVGP to run the above data. This is a very newly integrated feature and has therefore no thin wrapper yet in the GPy.models
module.
The likelihoods of GPy are located at GPy.likelihoods